package com.starinside.wp.controller;

import com.starinside.wp.domain.WxUser;
import com.starinside.wp.foundation.model.StatusResponse;
import com.starinside.wp.utils.HttpClient;
import com.starinside.wp.utils.JsonUtil;
import com.starinside.wp.utils.RemoteCallUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/aboutVisit")
@Api(tags = "预约到访")
public class CrmVisitApiController {


    @Value("${server.crm.url}")
    private String crmServerURL;



    /**
     * 获取预约试托列表
     */
    @PostMapping("/getList")
    public StatusResponse getList(@RequestBody Map aboutPallet) throws IOException {
        String json = HttpClient.doPost(crmServerURL + "/api/aboutVisit/getList",aboutPallet);
        Map map = JsonUtil.readToMap(json);
        return StatusResponse.success(map.get("data"));
    }


    /**
     * 添加预约试托
     */
    @PostMapping("/wpAdd")
    public Map add(@RequestBody Map aboutVisit) throws IOException {
        String json = HttpClient.doPost(crmServerURL + "/api/aboutVisit/wpAdd",aboutVisit);
        Map map = JsonUtil.readToMap(json);
        return map;

    }


    /**
     * 修改预约试托
     */
    @PostMapping("/wpUpdate")
    public StatusResponse wpUpdate(@RequestBody Map aboutVisit,HttpServletRequest req) {
        HashMap result = RemoteCallUtil.call(crmServerURL + "/api/aboutVisit/wpUpdate", aboutVisit, null, HashMap.class, "修改失败");
        return StatusResponse.success(result);
    }

    /**
     * 删除预约试托
     */
    @GetMapping ("/wpDelete")
    public void delete(String id) {
        Map p = new HashMap();
        p.put("id",id);
        HashMap result = RemoteCallUtil.call(crmServerURL + "/api/aboutVisit/delete", p, null, HashMap.class, "删除失败");
    }

}
